<?php
	define('DIR_SEP','/');
	//define('DIR_SEP','\\\\');
	define ('BASE_PATH', dirname(__FILE__).DIR_SEP);
	define('LIB_PATH', BASE_PATH.'lib'.DIR_SEP);
	define('CONTROLLER_PATH', BASE_PATH.'controllers'.DIR_SEP);
	define('CONFIG_PATH', BASE_PATH.'config'.DIR_SEP);
	define('VIEWS_PATH', BASE_PATH.'views'.DIR_SEP);
	define('MODELS_PATH', BASE_PATH.'models'.DIR_SEP);
	
	include LIB_PATH.'loader.php';
	
	if(!Loader::load('route')) {
		echo '<br>ERROR: unable to load the router library';
		echo '<br>Please check that LIB_PATH is correct';
		exit();
	}
	
	$route = new Route();
	$controller	=	$route->getController();
	$function	=	$route->getMethod();
	$params		=	$route->getParams();
	
	if(!Loader::load('config')) {
		echo '<br>ERROR: unable to load the config library';
		echo '<br>Please check that LIB_PATH is correct';
		exit();
	}
	if(!Loader::load('helper')) {
		echo '<br>ERROR: unable to load the helper library';
		echo '<br>Please check that LIB_PATH is correct';
	}
	if(!Loader::load('caller')) {
		echo '<br>ERROR: unable to load the controller caller library';
		echo '<br>Please check that LIB_PATH is correct';
		exit();
	}
	if(!Loader::load('controller')) {
		echo '<br>ERROR: unable to load the parent controller library';
		echo '<br>Please check that LIB_PATH is correct';
		exit();
	}
	if(!Loader::load('model')) {
		echo '<br>ERROR: unable to load the parent model library';
		echo '<br>Please check that LIB_PATH is correct';
		exit();
	}
	if(!Loader::load('database')) {
		echo '<br>ERROR: unable to load the database library';
		echo '<br>Please check that LIB_PATH is correct';
		exit();
	}
	if(!Loader::load('session')) {
		echo '<br>ERROR: unable to load the sessions library';
		echo '<br>Please check that LIB_PATH is correct';
		exit();
	}
	
	/*
	 * Load user libraries here
	 * eg. Loader::load('myclass');
	 */
	
	
	
	/*
	 * Start routing
	 */
	$conf = new Config();
	
	if(!$controller) {
		$controller = $conf->item('default_controller');
	}
	if(!$function) {
		$function = 'index';
	}
	$call = new Caller($controller, $function, $params);
?>
